package com.lc.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lc.dao.BaseMapper;
import com.lc.entity.Page;

public class BaseServiceImpl<P extends BaseMapper<T>, T> implements BaseService<T>{
	
	@Autowired
	protected P mapper;
	
	@Override
	public T selectOne(Object obj) {
		return mapper.selectOne(obj);
	}

	@Override
	public List<T> select(Object obj) {
		return mapper.select(obj);
	}

	@Override
	public PageInfo<T> selectByPage(Object obj, Page page) {
		if (page == null || page.getPageNum() <= 0 || page.getPageSize() <= 0) {
			page = new Page(1, 10);
		}
		PageHelper.startPage(1, 10);
		List<T> tss = mapper.select(obj);
		PageInfo<T> info = new PageInfo<T>(tss); 
		return info;
	}

	@Override
	public int insert(T t) {
		return mapper.insert(t);
	}

	@Override
	public int update(T t) {
		return mapper.update(t);
	}

	@Override
	public int delete(Object obj) {
		return mapper.delete(obj);
	}
	
}
